#! /usr/bin/env python
# -*- coding: utf8 -*-

# #portugues@ScoutLink 2006 JOTI Bot (slbot)
# Copyright (c) 2006, ScoutLink #portugues team
# This source is released under the New BSD License. See the LICENSE file for further
# information.

# $Author: acoster $
# $Date: 2006-09-20 02:11:47 +0000 (Wed, 20 Sep 2006) $ 

__version__ = "$Revision: 19 $"
# $Source$


from twisted.plugin import IPlugin
from zope.interface import implements
from slbot.slbot import __break_user__
from slbot.slinterface import ISLPlugin

class SLSignon:
	implements(IPlugin, ISLPlugin)

	author_name    = 'Alexandre Coster'
	author_email   = 'acoster@ScoutLink.net'
	author_webpage = 'http://acoster.net/'
	plugin_name    = 'Signon actions'
	plugin_version = '0.1'

	def register_me(self, b):
		self.bot = b
		b.reg_plugin("signon", self)
		if b.cfg.has_option("signon", "nickpass"):
			b.reg_plugin("notice", self)

	def signon(self):
		if self.bot.cfg.has_option("signon", "channels"):
			channels = self.bot.cfg.get("signon", "channels").split(',')
			for i in channels:
				self.bot.join(i.strip())

	def notice(self, user, chan, msg):
		if user.find('@') == -1:
			return
		u = __break_user__(user)
		if u[0].lower() == 'nickserv':
			self.bot.sendLine("NICKSERV IDENTIFY %s" % (self.bot.cfg.get("signon", "nickpass"),))

plugin = SLSignon()
